package cn.gzjp.modules.dt.service;

import java.util.List;

import cn.gzjp.modules.dt.entity.Question;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.gzjp.common.persistence.Page;
import cn.gzjp.common.service.CrudService;
import cn.gzjp.modules.dt.entity.TestRecord;
import cn.gzjp.modules.dt.dao.TestRecordDao;

/**
 * 练习记录Service
 *
 * @author zengcp
 * @version 2018-02-24
 */
@Service
@Transactional(readOnly = true)
public class TestRecordService extends CrudService<TestRecordDao, TestRecord> {

    public TestRecord get(String id) {
        return super.get(id);
    }

    public List<TestRecord> findList(TestRecord testRecord) {
        return super.findList(testRecord);
    }

    public Page<TestRecord> findPage(Page<TestRecord> page, TestRecord testRecord) {
        return super.findPage(page, testRecord);
    }

    @Transactional(readOnly = false)
    public void save(TestRecord testRecord) {
        super.save(testRecord);
    }

    @Transactional(readOnly = false)
    public void delete(TestRecord testRecord) {
        super.deleteByLogic(testRecord);
    }

    public TestRecord findByOpenidAndQuestionId(String openid, Integer questionId) {
        TestRecord record = new TestRecord();
        record.setOpenid(openid);
        record.setQuestion(new Question(questionId));
        return dao.findByOpenidAndQuestionId(record);
    }

    public Integer getCorrectCount(String openid) {
        TestRecord record = new TestRecord();
        record.setOpenid(openid);
        return dao.getCorrectCount(record);
    }

    public Integer getErrorCount(String openid) {
        TestRecord record = new TestRecord();
        record.setOpenid(openid);
        return dao.getErrorCount(record);
    }

    public Integer getTotalCount(String openid) {
        TestRecord record = new TestRecord();
        record.setOpenid(openid);
        return dao.getTotalCount(record);
    }


}